﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Server
{
	public class SearchMusic
	{
		public static string[] S(string[] theText)
		{
			List<string> list = new List<string>();
			var arr=	math.Permutations(theText);
			for (int fullL = 0; fullL < arr.GetLength(0); fullL++)
			{
				string[] text = arr[fullL];
				var serverDate = new dataTools(configClass.databaseip, configClass.databaseusername, "music", configClass.databaseport, configClass.psw);

				var sdt = serverDate.ChaoticsearchAndList("V1", new string[] { "title", "artists", "album" }, text);
				if (sdt.kind == "error")
					return new string[] { (string)sdt.msg };
				foreach (DataRow row in (DataRowCollection)sdt.msg)
				{
					if (list.Count > 30)
						return list.ToArray();
					string adds = row.ItemArray[1].ToString()+ "|"+row.ItemArray[2].ToString()+ "|" + row.ItemArray[3].ToString()+ "|" + row.ItemArray[6].ToString()+ "|" + row.ItemArray[9].ToString();

					if (!list.Exists(t=> t==adds))
			
						list.Add(adds);
					}

				}

			
			return list.ToArray();
		}
	}
}
